if {"bench" ni [info commands bench]} {
	package require bench
	namespace import bench::*
}

package require rl_json

namespace import rl_json::json

proc main {} {
bench as_json-1.1 {[json boolean] vs implicit} -setup { #<<<
} -compare {
	explicit {
		set doc {[]}
		for {set i 0} {$i < 10} {incr i} {
			json set doc end+1 [json boolean true]
		}
		set doc
	}

	implicit_literal {
		set doc {[]}
		for {set i 0} {$i < 10} {incr i} {
			json set doc end+1 true
		}
		set doc
	}

	implicit_var {
		set doc {[]}
		set v	true
		for {set i 0} {$i < 10} {incr i} {
			json set doc end+1 $v
		}
		set doc
	}

	implicit_parsed {
		set doc {[]}
		for {set i 0} {$i < 10} {incr i} {
			json set doc end+1 [string trim " true"]
		}
		set doc
	}
} -cleanup {
	unset -nocomplain doc i v
} -result {[true,true,true,true,true,true,true,true,true,true]}
#>>>
bench as_json-2.1 {[json number] vs implicit} -setup { #<<<
} -compare {
	explicit {
		set doc {[]}
		for {set i 0} {$i < 10} {incr i} {
			json set doc end+1 [json number $i]
		}
		set doc
	}

	implicit_var {
		set doc {[]}
		for {set i 0} {$i < 10} {incr i} {
			json set doc end+1 $i
		}
		set doc
	}

	implicit_parsed {
		set doc {[]}
		for {set i 0} {$i < 10} {incr i} {
			json set doc end+1 " $i"
		}
		set doc
	}
} -cleanup {
	unset -nocomplain doc i
} -result {[0,1,2,3,4,5,6,7,8,9]}
#>>>
bench as_json-2.2 {[json number] vs implicit} -setup { #<<<
} -compare {
	explicit {
		set doc {[]}
		for {set i 0} {$i < 10} {incr i} {
			json set doc end+1 [json number 1e$i]
		}
		set doc
	}

	implicit_var {
		set doc {[]}
		for {set i 0} {$i < 10} {incr i} {
			json set doc end+1 1e$i
		}
		set doc
	}
} -cleanup {
	unset -nocomplain doc i
} -match glob -result *
# -result {[1e0,1e1,1e2,1e3,1e4,1e5,1e6,1e7,1e8,1e9]}
# -result {[1.0,10.0,100.0,1000.0,10000.0,100000.0,1000000.0,10000000.0,100000000.0,1000000000.0]}
#>>>
bench as_json-3.2 {[json string] vs implicit} -setup { #<<<
} -compare {
	explicit {
		set doc {[]}
		for {set i 0} {$i < 10} {incr i} {
			json set doc end+1 [json string false$i]
		}
		set doc
	}

	implicit_var {
		set doc {[]}
		for {set i 0} {$i < 10} {incr i} {
			json set doc end+1 false$i
		}
		set doc
	}
} -cleanup {
	unset -nocomplain doc i
} -result {["false0","false1","false2","false3","false4","false5","false6","false7","false8","false9"]}

}

main
# vim: ft=tcl foldmethod=marker foldmarker=<<<,>>> ts=4 shiftwidth=4
